import utils from "../../../utils/utils";

import ActionButton from "../../../components/ActionButton.vue";
import QueryForm from "../../../components/QueryForm.vue";
import JmTable from "../../../components/JmTable.vue";
 
export default {
  name: "menu",
  components:{ActionButton,QueryForm,JmTable},
    data() {
        return {
       
            showModal: false,//表单是否显示
            edit_id:10,
            extend: {
                    index_url: 'auth/admin/index',
                    add_url: 'auth/admin/add',
                    edit_url: 'auth/admin/edit',
                    del_url: 'auth/admin/del',
                    multi_url: 'auth/admin/multi',
                },
            dataList:  [],
            page:{
                total:500,
                pageSize:10 
            },  
            ids:[],
            columns: [ 
                    {label: "#",        prop: "id",  width: 150, type:"selection"   }, 
                    {label: "标题",  prop: "title",},
                    {label: "商品图标",      prop: "icon",  type:"icon" ,},  
                    {label: "接口",  prop: "apipath", },
                    {label: "前端路由",  prop: "name", },
                    {label: "父id",  prop: "pid", },
                    {label: "权限",  prop: "weigh", },
                    {
                      label: "菜单状态",
                      prop: "status",
                      width: 90,
                      formatter(row, column, value) {
                        return {
                          "norma": "正常",
                          "hidden": "停用",
                        }[value];
                      },
                    }, 
                  
                    {label: "创建时间",  prop: "create_time",  
                       },
                ],//行参数
        }
    }, 
    mounted() {
    this.getDataList();
  },
  methods: {
    // 菜单列表初始化
    async getDataList() { 
        // let dataList= getMockDataList(); 
        // this.dataList =dataList.data;
        const res =   await this.$api.getRule({page:this.page.page,limit:this.page.pageSize});  
        this.dataList =res.rows;
        this.page.total=res.total
    },
       //分页的时候获取数据
    async  handleCurrentChange(val) {
   
        let list = await this.$api.getRule({page:val,limit:this.page.pageSize});
        this.dataList = list.rows;
        this.page.total=list.total; 
      },
      async del(_id){
    
          //  await this.$api.menuSubmit({ _id, action: "delete" });
          /*查看单条数据*/
          await this.$api.delRule({ids:_id}); 

            // console.log('id',_id);
           this.getDataList();
           
           this.$message.success("删除成功2");
        },
    // 新增菜单
    add(type, row) {
      this.showModal = true;
      this.action = "add";
      
				this.$router.push('/rule/add')
      // if (type == 2) {/rule/edit
      //   this.menuForm.pid = [...row.pid, row._id].filter(
      //     (item) => item
      //   );
      // }
    },
    //修改
    edit(row) {
        this.showModal = true;
        this.action = "edit";
        this.edit_id=row
        
      console.log(this.edit_id,row,"传值");
				this.$router.push('/rule/edit')
      // this.showModal = true;
      // this.action = "edit";
      // this.$nextTick(() => {
      //   Object.assign(this.menuForm, row);
      // });
    },
    
    //删除
    async alldel(_id) {
       
      console.log(this.ids);
      //   this.$message.success("删除成功all");
      
      var ids = "";
      for (let item of this.ids) {
        ids += item+ ",";
      }
      //去掉最后一个逗号(如果不需要去掉，就不用写)
      if (ids.length > 0) {
        ids = ids.substr(0, ids.length - 1);
      }
   
      await this.$api.delRule({ids:ids}); 
       
      //   // console.log('id',_id);
       this.getDataList();
       
       this.$message.success("删除成功2");
   
    },
    // 菜单操作-提交
    async handleSubmit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          let { action, menuForm } = this;
          let params = { ...menuForm, action };
          let res = await this.$api.menuSubmit(params);
          this.showModal = false;
          this.$message.success("操作成功");
          this.handleReset("dialogForm");
          this.getMenuList();
        }
      });
    },
    setids(ids){
        this.ids=ids
    },
    // 弹框关闭
    handleClose() {
      this.showModal = false;
      this.getDataList();
      this.$router.push('/rule')
      this.handleReset("dialogForm");
    },
    closeDialog() {
      this.showModal = false;
      this.getDataList();
      this.$router.push('/rule')
      this.handleReset("dialogForm");
    }
  },
};